package com.groupfifteen.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.groupfifteen.entity.ExamrewrongquestionEntity;
import com.groupfifteen.service.ExamrewrongquestionService;
import com.groupfifteen.vo.ExamrewrongquestionVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("examrewrongquestion/info")
public class ExamrewrongquestionController {
    @Autowired
    private ExamrewrongquestionService examrewrongquestionService;

    @PostMapping("/query")
    public IPage Query(@RequestBody ExamrewrongquestionVo examrewrongquestionVo) {

        ExamrewrongquestionEntity examrewrongquestionEntity = new ExamrewrongquestionEntity();
        examrewrongquestionEntity.setId(examrewrongquestionVo.getId());
        examrewrongquestionEntity.setYonghuId(examrewrongquestionVo.getYonghuId());
        examrewrongquestionEntity.setExampaperId(examrewrongquestionVo.getExampaperId());

        IPage<ExamrewrongquestionEntity> page = examrewrongquestionService.Query(examrewrongquestionEntity,1,10);
        return page;
    }

    @PostMapping("addexamrewrongquestion")
    public String AddSysUser(@RequestBody ExamrewrongquestionEntity examrewrongquestionEntity) {
        Integer result = examrewrongquestionService.AddExamrewrongquestion(examrewrongquestionEntity);
        if (result > 0) {
            return "success";
        } else {
            return "fail";
        }
    }

    @DeleteMapping("/deleteexamrewrongquestion/{id}")
    public String DeleteExamrewrongquestion(@PathVariable("id") Integer id) {
        Integer result = examrewrongquestionService.DeleteExamrewrongquestion(id);
        if (result > 0) {
            return "success";
        } else {
            return "fail";
        }
    }

    @GetMapping("/getexamrewrongquestion/{id}")
    public ExamrewrongquestionEntity GetExamrewrongquestion(@PathVariable("id") Integer id) {
        ExamrewrongquestionEntity result = examrewrongquestionService.GetExamrewrongquestion(id);
        if (result != null) {
            return result;
        } else {
            return null;
        }
    }

    @PutMapping("/updateexamrewrongquestion/{id}")
    public String UpdateExamrewrongquestion(@PathVariable("id") int id,@RequestBody ExamrewrongquestionEntity examrewrongquestionEntity) {
        examrewrongquestionEntity.setId(id);
        Integer result = examrewrongquestionService.UpdateExamrewrongquestion(examrewrongquestionEntity);
        if (result > 0) {
            return "success";
        } else {
            return "fail";
        }
    }

    @PostMapping("getinfo")
    public String Getinfo() {
        return "success";
    }

}
